home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 201-220 / scopedisk209 / infobar / infobar.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  5KB  |  237 lines

  1. /*
  2.   InfoBar.c - by Rj Schack.
  3.   Placed in the public domain.
  4.  
  5.   07 November 91 - v0.01 - Initial and final release.
  6.  
  7.   SAS/C (5.10b):
  8.     LC -cfist -O InfoBar.c
  9.  
  10.   BLink (5.10b):
  11.     FROM LIB:cback.o+InfoBar.o TO InfoBar LIB LIB:lc.lib LIB:amiga.lib 
  12.      DEFINE __main=__tinymain SC SD ND
  13. */
  14.  
  15. #include <dos.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <exec/types.h>
  20. #include <exec/memory.h>
  21. #include <graphics/gfxbase.h>
  22. #include <intuition/intuition.h>
  23. #include <proto/exec.h>
  24. #include <proto/graphics.h>
  25. #include <proto/intuition.h>
  26. #include <proto/dos.h>
  27.  
  28. /********************** DEFINES AND TYPEDEFS ***********************/
  29.  
  30. #define RPort IBWindow->RPort
  31.  
  32. #define Prototype
  33. typedef unsigned char uchar;
  34. typedef unsigned long ulong;
  35. typedef unsigned char text;
  36.  
  37. /********************* PROTOTYPES AND MACROS ***********************/
  38.  
  39. Prototype int  CXBRK(void);
  40. int CXBRK() { return(0); }
  41.  
  42. Prototype void CleanExit(void);
  43. Prototype void Initialize(void);
  44. Prototype int  main(int, text *[]);
  45. Prototype void MainLoop(void);
  46.  
  47. /**************** DATA STRUCTURES AND GLOBAL DATA ******************/
  48.  
  49. long _stack = 2048L;
  50. char *_procname = "InfoBar";
  51. long _priority = 0;
  52. long _BackGroundIO = 1;
  53. extern BPTR _Backstdout;
  54.  
  55. struct NewWindow IBWindowType =
  56. {
  57.   2, 1, 514, 10, 2, 1, MENUPICK,
  58.   SMART_REFRESH|BACKDROP|BORDERLESS,
  59.   NULL, NULL, NULL, NULL, NULL, NULL,
  60.   NULL, NULL, NULL, WBENCHSCREEN
  61. };
  62.  
  63. struct IntuiText QuitText =
  64. {
  65.   2, 1, JAM2, 2, 1, NULL, " Quit", NULL
  66. };
  67.  
  68. struct MenuItem QuitMenu =
  69. {
  70.   NULL, 0, 0, 65, 10, ITEMTEXT|ITEMENABLED|HIGHCOMP,
  71.   0, (APTR) &QuitText, NULL, NULL, NULL, MENUNULL
  72. };
  73.  
  74. struct Menu ProjectMenu =
  75. {
  76.   NULL, 0, 0, 65, 0, MENUENABLED, "Project", &QuitMenu
  77. };
  78.  
  79. struct IntuitionBase *IntuitionBase;
  80. struct GfxBase       *GfxBase = NULL;
  81. struct Window        *IBWindow = NULL;
  82.  
  83. /*************************** MAIN BODY *****************************/
  84.  
  85. int main(argc, argv)
  86. int argc;
  87. text *argv[];
  88. {
  89.   Initialize();
  90.   MainLoop();
  91.   CleanExit();
  92. }
  93.  
  94. void Initialize()
  95. {
  96.   if (!(IntuitionBase = (struct IntuitionBase *)
  97.    OpenLibrary("intuition.library", 0)))
  98.   {
  99.     if (_Backstdout)
  100.       Write(_Backstdout, "Couldn't open intuition.library.", 32);
  101.     CleanExit();
  102.   }
  103.  
  104.   if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0)))
  105.   {
  106.     if (_Backstdout)
  107.       Write(_Backstdout, "Couldn't open graphics.library.", 31);
  108.     CleanExit();
  109.   }
  110.  
  111.   if (!(IBWindow = (struct Window *) OpenWindow(&IBWindowType)))
  112.   {
  113.     if (_Backstdout)
  114.       Write(_Backstdout, "Couldn't open window.", 21);
  115.     CleanExit();
  116.   }
  117.  
  118.   SetAPen(RPort, 1); RectFill(RPort, 0, 0, 614, 10);
  119.   SetAPen(RPort, 0); SetBPen(RPort, 1);
  120.   Move(RPort, 121, 7); Text(RPort, "DATE:", 5);
  121.   Move(RPort, 225, 7); Text(RPort, "CHIP:", 5);
  122.   Move(RPort, 327, 7); Text(RPort, "RAM:", 4);
  123.   Move(RPort, 423, 7); Text(RPort, "TIME:", 5);
  124.   SetMenuStrip(IBWindow, &ProjectMenu);
  125.   ShowTitle(IBWindow->WScreen, FALSE);
  126.   SetAPen(RPort, 2);
  127.  
  128.   if (_Backstdout)
  129.     Close(_Backstdout);
  130. }
  131.  
  132. void MainLoop()
  133. {
  134.   struct IntuiMessage *IntMsg;
  135.   uchar DateStr[6], ChipStr[8], RAMStr[8], TimeStr[6], toggle = 1;
  136.   uchar Clock[8], PDay = 0;
  137.   ulong Chip, RAM, PChip = 0, PRAM = 0;
  138.  
  139.   while (1)
  140.   {
  141.     if (IntMsg = (struct IntuiMessage *) GetMsg(IBWindow->UserPort))
  142.     {
  143.       if (IntMsg->Code != MENUNULL)
  144.       {
  145.         ReplyMsg((struct Message *) IntMsg);
  146.         break;
  147.       }
  148.     }
  149.  
  150.     Chip = AvailMem(MEMF_CHIP);
  151.     RAM = AvailMem(MEMF_FAST) + Chip;
  152.  
  153.     if (Chip != PChip)
  154.     {
  155.       stcl_d(ChipStr, Chip);
  156.  
  157.       if (Chip > 1000000)
  158.       { ChipStr[4] = 'k'; ChipStr[5] = 0x00; }
  159.       else
  160.       if (Chip > 100000)
  161.       { ChipStr[3] = 'k'; ChipStr[4] = 0x00; strins(ChipStr, " "); }
  162.       else
  163.       if (Chip > 10000)
  164.       { ChipStr[2] = 'k'; ChipStr[3] = 0x00; strins(ChipStr, "  "); }
  165.       else
  166.       if (Chip > 1000)
  167.       { ChipStr[1] = 'k'; ChipStr[2] = 0x00; strins(ChipStr, "   "); }
  168.       else
  169.         strcpy(ChipStr, "  <1k");
  170.  
  171.       Move(RPort, 271, 7);
  172.       Text(RPort, ChipStr, 5);
  173.       PChip = Chip;
  174.     }
  175.  
  176.     if (RAM != PRAM)
  177.     {
  178.       stcl_d(RAMStr, RAM);
  179.  
  180.       if (RAM > 1000000)
  181.       { RAMStr[4] = 'k'; RAMStr[5] = 0x00; }
  182.       else
  183.       if (RAM > 100000)
  184.       { RAMStr[3] = 'k'; RAMStr[4] = 0x00; strins(RAMStr, " "); }
  185.       else
  186.       if (RAM > 10000)
  187.       { RAMStr[2] = 'k'; RAMStr[3] = 0x00; strins(RAMStr, "  "); }
  188.       else
  189.       if (RAM > 1000)
  190.       { RAMStr[1] = 'k'; RAMStr[2] = 0x00; strins(RAMStr, "   "); }
  191.       else
  192.         strcpy(RAMStr, "  <1k");
  193.  
  194.       Move(RPort, 367, 7);
  195.       Text(RPort, RAMStr, 5);
  196.       PRAM = RAM;
  197.     }
  198.  
  199.     if (toggle)
  200.     {
  201.       getclk(&Clock[0]);
  202.  
  203.       if (Clock[3] != PDay)
  204.       {
  205.         sprintf(DateStr, "%02d/%02d", Clock[2], Clock[3]);
  206.         Move(RPort, 169, 7);
  207.         Text(RPort, DateStr, 5);
  208.         PDay = Clock[3];
  209.       }
  210.  
  211.       sprintf(TimeStr, "%02d:%02d", Clock[4], Clock[5]);
  212.       Move(RPort, 471, 7);
  213.       Text(RPort, TimeStr, 5);
  214.  
  215.       toggle--;
  216.     }
  217.     else
  218.     {
  219.       Move(RPort, 487, 7);
  220.       Text(RPort, " ", 1);
  221.       toggle++;
  222.     }
  223.  
  224.     Delay(50);
  225.   }
  226. }
  227.  
  228. void CleanExit()
  229. {
  230.   if (IBWindow)      ClearMenuStrip(IBWindow);
  231.   if (IBWindow)      CloseWindow(IBWindow);
  232.   if (GfxBase)       CloseLibrary((struct Library *) GfxBase);
  233.   if (IntuitionBase) CloseLibrary(IntuitionBase);
  234.  
  235.   exit(0);
  236. }
  237.